package com.xayy.mgt.controller;

import cn.kawins.base.result.ResultBody;
import cn.kawins.mybatis.base.BaseController;
import cn.kawins.spring.mvc.validator.Group;
import com.github.pagehelper.PageInfo;
import com.xayy.mgt.model.AssociationParameter;
import com.xayy.mgt.model.dto.NodeInfoDto;
import com.xayy.mgt.service.AssociationParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/glcs1")
@Api(tags = "关联参数")
public class AssociationParameterController extends BaseController<AssociationParameter> {

    @Resource
    private AssociationParameterService associationParameterService;

    @PostMapping("/save")
    @ApiOperation(value = "新增关联参数")
    public ResultBody saveAssociationParameter(@Validated(Group.Insert.class) @RequestBody AssociationParameter associationParameter) {
        return associationParameterService.saveAssociationParameter(associationParameter).body();
    }

    @DeleteMapping("/deleteAssociationParameter/{id}")
    @ApiOperation(value = "删除关联参数")
    public ResultBody deleteAssociationParameter(@ApiParam(value = "关联参数id", required = true) @PathVariable Long id) {
        return associationParameterService.deleteAssociationParameter(id).body();
    }

    @PutMapping("/updateAssociationParameter")
    @ApiOperation(value = "修改关联参数")
    public ResultBody updateAssociationParameter(@RequestBody AssociationParameter associationParameter) {
        return associationParameterService.updateAssociationParameter(associationParameter).body();
    }

    @PostMapping("/pageList")
    @ApiOperation(value = "关联参数信息（分页）", httpMethod = "POST")
    public ResultBody getAssociationParameterPageList(@RequestBody NodeInfoDto nodeInfoDto) {
        PageInfo<AssociationParameter> page = associationParameterService.pageList(nodeInfoDto);
        return ResultBody.success(page);
    }

    @GetMapping("/getAssociationParameterDetail/{associationParameterId}")
    @ApiOperation(value = "查看关联参数详情", httpMethod = "GET")
    public ResultBody getAssociationParameterDetail(@PathVariable Long associationParameterId) {
        AssociationParameter associationParameter =
            associationParameterService.getAssociationParameterDetail(associationParameterId);
        return ResultBody.success(associationParameter);
    }

    @GetMapping("/getParamList/{type}/{nodeId}")
    @ApiOperation(value = "关联参数配置根据不同类型返回参数列表1：遥测2：功能3：性能4：健康度", httpMethod = "GET")
    public ResultBody getParamList(@ApiParam(value = "1：遥测2：功能3：性能4：健康度") @PathVariable Integer type,
        @ApiParam(value = "节点id") @PathVariable Long nodeId) {
        return associationParameterService.getParamList(type, nodeId).body();
    }
}
